import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/operationLog',
    component: Layout,
    redirect: '/operationLog/opLog',
    name: 'OperationLog',
    meta: {title: '操作日志', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'opLog',
        name: 'OpLog',
        component: () => import('@/views/OperationLog/index.vue'),
        meta: {title: '操作日志', icon: 'el-icon-user-solid'}
      },
    ]
  },

  {
    path: '/user-management',
    component: Layout,
    redirect: '/user-management/user-info',
    name: 'UserManagement',
    meta: {title: '用户管理系统', icon: 'el-icon-s-help', alwaysShow: true},
    children: [
      {
        path: 'user-info',
        name: 'UserInfo',
        component: () => import('@/views/user/UserINFO.vue'),
        meta: {title: '用户信息', icon: 'el-icon-user-solid'}
      },
    ]
  },
  {
    path: '/comment-management',
    component: Layout,
    redirect: '/comment-management/user-comment',
    name: 'CommentManagement',
    meta: {title: '评论管理', icon: 'el-icon-s-help', alwaysShow: true},
    children: [
      {
        path: 'user-comment',
        name: 'Usercomment',
        component: () => import('@/views/comment/Usercomment.vue'),
        meta: {title: '租房讨论', icon: 'el-icon-user-solid'}
      },
    ]
  },
  {
    path: '/user-taolunManag',
    component: Layout,
    redirect: '/user-taolunManag/user-taolun',
    name: 'TaolunManagement',
    meta: {title: '资讯评论', icon: 'el-icon-s-help', alwaysShow: true},
    children: [
      {
        path: 'user-taolun',
        name: 'Usertaolun',
        component: () => import('@/views/touristguide/Taolun.vue'),
        meta: {title: '租房攻略', icon: 'el-icon-user-solid'}
      },
    ]
  },
  {
    path: '/room',
    component: Layout,
    redirect: '/room',
    name: 'Room',
    meta: {title: '房屋管理', icon: 'room'},
    children: [
      {
        path: 'room',
        name: 'Room',
        component: () => import('@/views/room/index.vue'),
        meta: {title: '房间', icon: 'house'}
      },
      {
        path: '',
      }
    ]
  },

  {
    path: '/OccupancyInfo',
    component: Layout,
    name: 'OccupancyInfo',
    meta: {title: '入住信息管理', icon: 'occupancyInfo'},
    children: [
      {
        path: 'index',
        name: 'OccupancyInfo',
        component: () => import('@/views/HousingOccupancyInfo/index.vue'),
        meta: {title: '入住信息', icon: 'occupancy'}
      },
      {
        path: '',
      }
    ]
  },

  {
    path: '/reservationInfo',
    component: Layout,
    name: 'ReservationInfo',
    meta: {title: '预约信息管理', icon: 'reservation'},
    children: [
      {
        path: 'index',
        name: 'ReservationInfo',
        component: () => import('@/views/reservationInfo/index.vue'),
        meta: {title: '预约信息', icon: 'reservationInfo'}
      },
      {
        path: '',
      }
    ]
  },
  // {
  //   path: '/echarts',
  //   component: Layout,
  //   name: 'ECharts',
  //   meta: {title: 'Echarts', icon: 'reservation'},
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'ECharts',
  //       component: () => import('@/views/ECharts/index.vue'),
  //       meta: {title: 'Echarts', icon: 'reservationInfo'}
  //     },
  //     {
  //       path: '',
  //     }
  //   ]
  // },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: {title: 'Example', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'Landlord',
        name: '房东信息管理',
        component: () => import('@/views/Landlord/index'),
        meta: {title: '房东信息管理', icon: 'table'}
      },
      {
        path: 'Tree',
        name: '房屋类型管理',
        component: () => import('@/views/tree/index'),
        meta: {title: '房屋类型管理', icon: 'tree'}
      },
      {
        path: 'AntiFraud',
        name: '反诈宣传',
        component: () => import('@/views/fraud/AntiFraud.vue'),
        meta: {title: '反诈宣传', icon: 'tree'}
      }
    ]
  },
  {
    path: '/zf',
    component: Layout,
    redirect: '/zf/order/manage',
    name: 'ZF',
    meta: {title: '预约租房订单管理', icon: 'el-icon-s-help', alwaysShow: true},
    children: [
      {
        path: 'order/manage',
        name: 'OrderManage',
        component: () => import('@/views/zf/YuYueOrderManage/index.vue'),
        meta: {title: '预约订单信息', icon: 'tree'}
      }
    ]
  },

  {
    path: '/zf2',
    component: Layout,
    redirect: '/zf2/order/info',
    name: 'ZF2',
    meta: {title: '订单信息管理', icon: 'el-icon-s-tools', alwaysShow: true},
    children: [
      {
        path: 'order/info',
        name: 'OrderInfo',
        component: () => import('@/views/zf/OrderInfoManage/index.vue'),
        meta: {title: '订单信息', icon: 'tree'}
      }
    ]
  },

  {
    path: '/profile',
    name: 'Profile',
    component: () => import('@/views/profile/index')
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
